<%--
  Created by IntelliJ IDEA.
  User: Lxy
  Date: 2018/11/5
  Time: 13:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>文件上传</title>
    <script type="text/javascript" src="../base/jquery-3.3.1.min.js"></script>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data" id="form_file">
    <input type="file" name="file">
    <input type="submit" name="表单上传">
    <input type="button" value="ajax上传">
</form>


<form action="/uploads" method="post" enctype="multipart/form-data" id="form_files">
    <input type="file" name="files" multiple>
    <input type="submit" name="表单上传">
    <input type="button" value="ajax上传">
</form>
</body>
<script>
    $(function () {
        $("#form_file input[type=button]").click(function () {
            var form=new FormData($("#form_file")[0]);
            form.append("newName","name");
            $.ajax({
                url:"/upload",
            type:"post",
            data:form,
                contentType: false,
                processData: false,
                success:function (data) {
                console.log(data);
                alert(data.message);
                window.location.reload();
                },
                error:function (data) {
                    console.log(data);
                }
            })
        });
    })
</script>


<script>
    $(function () {
        $("#form_file input[type=button]").click(function () {
            var form=new FormData($("#form_files")[0]);
            form.append("newName","name");
            $.ajax({
                url:"/uploads",
                type:"post",
                data:form,
                contentType: false,
                processData: false,
                success:function (data) {
                    console.log(data);
                    alert(data.message);
                    window.location.reload();
                },
                error:function (data) {
                    console.log(data);
                }
            })
        });
    })
</script>
</html>
